/* File name: BufferedFPGALoopBack.c

	04Dec2007 .. initial version .. KMetzger

*/


#define xsize 352 
#define ysize 288


#include<stdio.h>
#include<math.h>
#include "detection.h"
#include "im2a.h"
#include "control.h"
#include "thresh.h"

#define FRAME_SIZE 25000


unsigned long McBSP0_slave(unsigned long Value);
void McBSP0_slave_setup(int ws);

void setup_buffered_McBSP0(void);
unsigned GetFromMcBSP0(void);
void SendToMcBSP0(unsigned);

#pragma DATA_SECTION(frame_array, "SDRAMC");
unsigned int frame_array[FRAME_SIZE];

#pragma DATA_SECTION(frame_array2, "SDRAMD");
unsigned int frame_array2[FRAME_SIZE];


// this won't work because it spans more than one page (>64 K)

//#pragma DATA_SECTION(frame_pixel_array, "SDRAMD");
//short frame_pixel_array[FRAME_SIZE*2];


void main(void)
{

	

	unsigned utemp;
	unsigned int i=0;
	int go = 0;

	//FILE *fid;
	//fid = fopen("pimp1.txt","w");

	McBSP0_slave_setup(16);
		
	while(1){

	while(i<50000)
	{
		utemp = McBSP0_slave(0);
		
		if (go == 1 & i<25000)
		{
			frame_array[i]= utemp;
			i++;
		}
		else if (go == 1 & i>=25000)
		{
			frame_array2[i-25000] = utemp;
			i++;
		}

		if (utemp == 65535)
		{
			go = 1;
		}
		
	}

	//printf("Done reading one frame from fpga \n");

	i=0;		
	
	while(i<FRAME_SIZE)
	{	
		//fprintf(fid,"%u\n",frame_array[i]);
		i++;
	}	

	i=0;		
	
	while(i<FRAME_SIZE)
	{	
	//
		//fprintf(fid,"%u\n",frame_array2[i]);
		i++;
	}
	}

//	//printf("Done pimpin' (done writin to file) \n");

//	fclose(fid);
}





